import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class WechatMenuService extends BaseService<any> {
  private readonly logger = new Logger(WechatMenuService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getInfo
   * 对应 PHP: WechatMenuService_admin::getInfo()
   * 逻辑类型: undefined - undefined
   */
  async getInfo() {
    // 基于PHP真实逻辑: getInfo
    // PHP原文: $core_config_service = new CoreConfigService();         return $core_config_service->getConfig($this->site_id, 'WECHAT_MENU')['value'] ?? [];     }   ...
const core_config_service = this.coreConfigService;
        return core_config_service.getConfig(this.site_id, 'WECHAT_MENU').value || [];
    }


    /**
     * 更新微信菜单
     * @param data
     * @return SysConfig|bool|Model
     * @throws GuzzleBusinessException
     * @throws InvalidConfigBusinessException
     */
    async edit(data){
        const core_wechat_api_service = this.coreWechatApiService;
        const menu_result = core_wechat_api_service.menuCreate(this.site_id, data);
        if(!!menu_result.errcode) && menu_result.errcode != 0)
            throw new WechatBusinessException(menu_result.errmsg];

        //先尝试改变微信接口菜单
        const core_config_service = this.coreConfigService;
        return core_config_service.setConfig(this.site_id, 'WECHAT_MENU', data);
    }
}
  }

  /**
   * edit
   * 对应 PHP: WechatMenuService_admin::edit()
   * 逻辑类型: undefined - undefined
   */
  async edit(data: any[]) {
    // 基于PHP真实逻辑: edit
    // PHP原文: $core_wechat_api_service = new CoreWechatApiService();         $menu_result = $core_wechat_api_service->menuCreate($this->site_id, $data);         if(...
const core_wechat_api_service = this.coreWechatApiService;
        const menu_result = core_wechat_api_service.menuCreate(this.site_id, data);
        if(!!menu_result.errcode) && menu_result.errcode != 0)
            throw new WechatBusinessException(menu_result.errmsg];

        //先尝试改变微信接口菜单
        const core_config_service = this.coreConfigService;
        return core_config_service.setConfig(this.site_id, 'WECHAT_MENU', data);
    }
}
  }
}
